package com.luccesit.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.luccesit.entity.Admin;
import com.luccesit.service.AdminService;
import com.luccesit.util.web.ServletUtil;

public class AdminLogin extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		AdminService as = new AdminService();
		
		String name = request.getParameter("username");
		String password = request.getParameter("password");
		
		if(name != null && password != null){
			Admin admin = as.login(name,password,ServletUtil.getIp(request));
			if(admin != null ){
				
				ServletUtil.setSessionAttribute(request,"session_admin",admin);
				ServletUtil.redirect(response,"/admin/home.jsp");
			}else{
				ServletUtil.redirect(response, "/index.jsp?state=10001");
			}
		}
	}
}
